<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  #div1 {
    width: 200px;
    height: 200px;
    background: red;
    border: 1px solid black;
  }
</style>

<script>
  window.onload = function () {
    let div1 = document.getElementById("div1")
    setInterval(() => {
      div1.style.width = parseInt(getStyle(div1, "width")) - 1 + "px"
    }, 30);
  }

  function getStyle(obj, name) {
    if (obj.currentStyle) {
      return obj.currentStyle[name];
    } else {
      return getComputedStyle(obj, '')[name];
    }
  }
</script>

<body>
  <div id="div1"></div>

</body>

</html>